home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CEL2SPR.ZIP / CEL2SPR.C < prev    next >
C/C++ Source or Header  |  1994-12-29  |  3KB  |  99 lines

  1. // Title      : Cel2spr - autodesk animator cel to sprite maker
  2. // Programmer : Phil Carlisle (Zoombapup // CodeX // Mage)
  3.  
  4. #include <stdio.h>
  5.  
  6. #define DEBUG
  7.  
  8. struct CelHeader {
  9.         unsigned short id;       // 1 word identifier
  10.         unsigned short width;    // word width
  11.         unsigned short height;   // word height
  12.         unsigned char other[26]; // pad out the header
  13.         unsigned char colourmap[768]; // colour data
  14.     };
  15.        
  16.         
  17.         
  18.  
  19.  
  20. void main(int argc, char **argv) {
  21.  
  22.     struct CelHeader chead;
  23.     FILE *celfile,*sprname;
  24.     int datasize;    
  25.     unsigned char plane1data[16000];
  26.     unsigned char plane2data[16000];
  27.     unsigned char plane3data[16000];
  28.     unsigned char plane4data[16000];
  29.     int planedata;
  30.     unsigned char chardatasize;
  31.     // main pep
  32.     printf("\ncel2spr - Internal Utility - (C) Phil Carlisle 1994\n\n");
  33.  
  34.     // check the command line for number of args..
  35.     if (argc < 3) {
  36.       printf("Incorrect number of parameters\n");
  37.       printf("Usage: Cel2spr <CELFILENAME> <SPRITEFILENAME>\n");
  38.       exit();
  39.     } /* if */
  40.  
  41.     // its a proper command line now open the cel file...
  42.     printf("Celfilename is ->%s \n",argv[1]);
  43.     celfile = fopen(argv[1],"r+b"); // open the goddam file
  44.     if (celfile==NULL)
  45.     {
  46.         printf("cannot open celfile, please check filename!\n");
  47.         exit();
  48.     };
  49.     
  50.     // and open the sprite file
  51.     printf("Spritefilename is ->%s \n",argv[2]);
  52.     sprname = fopen(argv[2],"w+b"); // open the goddam file
  53.     if (sprname==NULL)
  54.     {
  55.         printf("cannot open spritefile, please check filename!\n");
  56.         exit();
  57.     };
  58.     
  59.     // ok its open! now what??
  60.     rewind(celfile);     // set position to beggining of celfile
  61.     fread(&chead,sizeof(struct CelHeader),1,celfile);     // read the header
  62.     fwrite(&chead.width,sizeof(chead.width),1,sprname);   // write width 
  63.     fwrite(&chead.height,sizeof(chead.height),1,sprname); // write height   
  64.     
  65.     // ok, so celfile points to start of the data
  66.     datasize=(chead.width*chead.height);
  67.     
  68.     // print the info...
  69.     printf("Sprite Width  -> %hd \n",chead.width);
  70.     printf("Sprite Height -> %hd \n",chead.height);
  71.     printf("Datasize -> %d",datasize);
  72.  
  73. #ifdef debug
  74. //    
  75. #endif    
  76.     // setup plane data
  77.     for (planedata=0;planedata<(datasize/4);planedata++)
  78.     {
  79.     fread(&plane1data[planedata],sizeof(chardatasize),1,celfile);   // read the data byte
  80.     fread(&plane2data[planedata],sizeof(chardatasize),1,celfile);   // read the data byte
  81.     fread(&plane3data[planedata],sizeof(chardatasize),1,celfile);   // read the data byte
  82.     fread(&plane4data[planedata],sizeof(chardatasize),1,celfile);   // read the data byte
  83.     }
  84.     
  85.     
  86.     // finally write the data        
  87.     fwrite(&plane1data,(datasize/4),1,sprname); // write height   
  88.     fwrite(&plane2data,(datasize/4),1,sprname); // write height   
  89.     fwrite(&plane3data,(datasize/4),1,sprname); // write height   
  90.     fwrite(&plane4data,(datasize/4),1,sprname); // write height   
  91. #ifdef debug
  92. //    
  93. #endif    
  94.     
  95.     // finally close the goddam files :)
  96.     fclose(celfile);          
  97.     fclose(sprname);
  98. } /* main */
  99.